Does `adb install` do APK signature verification?


Question

When using adb install something.apk, does the Android Package Manager verify the signature of the APK? adb install seems to bring up nothing up on the phone's screen, so it's hard for me to know if it does.



I like the idea of using APK mirror websites to download APK files with a phone that does not have Google Play Services, but because I can't trust any of those APK mirror websites, I want to make sure that the app's data is not at risk if using adb install when upgrading to a new APK version.



A couple of questions:




  • If adb install does do signature verification, what does it do if the signature does not match? Does it fail the install, pop up a question on the phone's screen, or automatically erase the app's existing data?

  • What if using the -r option with adb install?

  • If I use adb uninstall -k before installing the app upgrade, does signature verification occur from the previous installation before the old app data will be shared with the new install?

  • Bonus: We have the option adb install -l, where -l stands for "forward-lock the app". What does this "forward-lock" mean, and does it have anything to do with signature verification and app data access?


Answer

You are correct adb install verifies the signature of the app.



If the app has not been installed on the device before the package manager can only verify that the app has been signed - who has signed the app can't be verified by the package manager.



Only if you install an update for an app that has already been installed before the package manager can check if the signature of the new app matches the already installed app. In case the "update.apk" to be installed has a different signature you will get an error message after executing adb install like




signatures do not match the previously installed version




I am not sure if this also happens in case you have installed the old app before using adb uninstall -k. I would assume (but have never tested it) that the signature is also checked and compared and only an apk with a matching signature can be installed. Otherwise you could get access to any app-private data on your phone by replacing the app with a custom app. This would be a serious security vulnerability.



If you additionally want to verify your downloaded apk files you can use apksigner which is included in the Android SDK. The necessary steps are described in this answer I wrote some time ago. Especially the verification of the publisher (check what other apps have been signed by the same entity) using androidobservatory.org and apkmirror.com may be of interest to you.



forward-lock in my understanding is if you want to pin an app to the current device firmware version, hence mark an app as potentially not compatible with future Android versions.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes